package com.quick.develop.flowable.framework.manager.identity;

import com.quick.develop.flowable.application.IBpmTaskAssigneeApplication;
import com.quick.develop.flowable.domain.vo.system.SysApiRole;
import com.quick.develop.flowable.framework.convert.definition.BpmGroupUserConvert;
import org.flowable.idm.api.Group;
import org.flowable.idm.engine.IdmEngineConfiguration;
import org.flowable.idm.engine.impl.GroupQueryImpl;
import org.flowable.idm.engine.impl.persistence.entity.GroupEntity;
import org.flowable.idm.engine.impl.persistence.entity.GroupEntityManagerImpl;
import org.flowable.idm.engine.impl.persistence.entity.data.GroupDataManager;
import org.springframework.context.annotation.Lazy;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author junyuan.liu
 * @description:  候选组查询改写
 * @date 2022/6/24 11:04
 */
public class CustomGroupEntityManager extends GroupEntityManagerImpl {
    @Resource
    @Lazy
    IBpmTaskAssigneeApplication bpmTaskAssigneeApplication;
    
    
    public CustomGroupEntityManager(IdmEngineConfiguration idmEngineConfiguration, GroupDataManager groupDataManager) {
        super(idmEngineConfiguration, groupDataManager);
    }

    @Override
    public GroupEntity findById(String entityId) {
        /*GroupQueryImpl aGroupQueryImpl = (GroupQueryImpl) new GroupQueryImpl().groupId(entityId);
        GroupEntity group = new GroupEntityImpl();
        group.setId("2");
        group.setName("普通角色");*/
        return null;
    }

    @Override
    public List<Group> findGroupByQueryCriteria(GroupQueryImpl query) {
        List<SysApiRole> list = bpmTaskAssigneeApplication.getUserRoles(query.getUserId());
        return BpmGroupUserConvert.INSTANCE.convertList2(list);
        /*GroupEntity group = new GroupEntityImpl();
        group.setId("2");
        group.setName("普通角色");
        return Collections.singletonList(group);*/
    }

    @Override
    public long findGroupCountByQueryCriteria(GroupQueryImpl query) {
        return 1L;
    }
}
